#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int n,m;
int lmt;
int y[N],ma[N],mi[N];
struct segment_tree{
    int ls[N*325],rs[N*325],ma[N*325],pcnt;
    void update(int &now,int l,int r,int p,int v){
        if(!now){
            now = ++pcnt;
        }
        ma[now] = max(ma[now],v);
        if(l == r){
            return;
        }
        int mid = (l + r)/2;
        if(p <= mid){
            update(ls[now],l,mid,p,v);
        }else{
            update(rs[now],mid+1,r,p,v);
        }
    }
    int query(int now,int l,int r,int x,int y){
        if(x <= l && r <= y){
            return ma[now];
        }
        int mid = (l + r)/2;
        int ma = 0;
        if(x <= mid){
            ma = max(ma,query(ls[now],l,mid,x,y));
        }
        if(mid < y){
            ma = max(ma,query(rs[now],mid+1,r,x,y));
        }
        return ma;
    }
} sg;
struct BIT{
    int rots[N];
    inline int lowbit(int x){
        return x&(-x);
    }
    void update(int now,int p,int v){
        for(int i = now;i <= n;i += lowbit(i)){
            sg.update(rots[i],1,lmt,p,v);
        }
    }
    int query(int now,int x,int y){
        int ma = 0;
        for(int i = now;i >= 1;i -= lowbit(i)){
            ma = max(sg.query(rots[i],1,lmt,x,y),ma);
        }
        return ma;
    }
}blt;
int main(){
    cin>>n>>m;
    for(int i = 1;i<=n;i++){
        cin>>y[i];
        lmt = max(lmt,y[i]);
        ma[i] = mi[i] = y[i];
    }
    for(int i = 1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        ma[x] = max(ma[x],y);
        mi[x] = min(mi[x],y);
        lmt = max(y,lmt);
    }
    int ans = 0;
    for(int i = 1;i<=n;i++){
        int map = blt.query(y[i],1,mi[i]);
        map++;
        ans = max(map,ans);
        blt.update(ma[i],y[i],map);
    }
    cout<<ans<<'\n';
}